package com.everyline.baselibrary.plate.adapter

import android.view.View
import androidx.cardview.widget.CardView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.everyline.baselibrary.R
import com.everyline.baselibrary.plate.bean.PlateItem
import java.util.ArrayList

/**
 *  @author:  hyzhan
 *  @date:    2019/7/22
 *  @desc:    TODO
 */
class CharAdapter(data:ArrayList<PlateItem>?): BaseMultiItemQuickAdapter<PlateItem, BaseViewHolder>(data) {

    init {
        addChildClickViewIds()
        addItemType(PlateItem.CHAR, R.layout.layout_plate_item)
        addItemType(PlateItem.EMPTY, R.layout.layout_plate_item)
        addItemType(PlateItem.DELETE, R.layout.layout_plate_delete)

    }


    override fun convert(helper: BaseViewHolder, item: PlateItem) {

        helper?.run {
            when (itemViewType) {
                PlateItem.CHAR -> {
                    convertChar(item)
                }
                PlateItem.EMPTY -> convertEmpty()
                PlateItem.DELETE -> {
                }
                else -> {

                }
            }
        }
    }


//    private fun BaseViewHolder.convertDelete() {
//        addOnClickListener(R.id.mIvDelete)
//    }

    private fun BaseViewHolder.convertEmpty() {
        itemView.findViewById<CardView>(R.id.mCvContainer).visibility = View.GONE
    }

    private fun BaseViewHolder.convertChar(item: PlateItem?) {
        setText(R.id.mTvWord, item?.data ?: "")
//        addOnClickListener(R.id.mTvWord)
    }
}